﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kaskelot.Services.Model;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.Mapping
{
	public static class StadsdelExtensions
	{
		public static DataContracts.Stadsdel ToContract(this Stadsdel entity)
		{
			DataContracts.Stadsdel b = new DataContracts.Stadsdel();

			CopyFromEntity(entity, b, false);

			return b;
		}

		public static DataContracts.Stadsdel ToMinimalContract(this Stadsdel entity)
		{
			DataContracts.Stadsdel b = new DataContracts.Stadsdel();

			CopyFromEntity(entity, b, true);

			return b;
		}

		public static Stadsdel ToEntity(this DataContracts.Stadsdel b)
		{
			Stadsdel entity = new Stadsdel();

			CopyToEntity(b, entity);

			return entity;
		}

		public static void UpdateEntity(this Stadsdel entity, DataContracts.Stadsdel b)
		{
			CopyToEntity(b, entity);
		}

		private static void CopyFromEntity(Stadsdel from, DataContracts.Stadsdel to, bool minimal)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;
			to.Namn = from.Benamning;
			
			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;

			if (minimal) return;
		}

		private static void CopyToEntity(DataContracts.Stadsdel from, Stadsdel to)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;
			to.Benamning = from.Namn;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;
		}
	}
}
